//index.js
Page({
  handleTap1:function(e){
    console.log(e);
  },
  handleTap2: function (e) {
    console.log(e);
  },
  handleTap3: function (e) {
    console.log(e);
  },
  handleTap4: function () {
    console.log(4);
  },
  addNumberToFront: function (e) {
    this.data.numberArray = [this.data.numberArray.length + 1].concat(this.data.numberArray)
    this.setData({
      numberArray: this.data.numberArray
    })
  },
  switch: function (e) {
    const length = this.data.objectArray.length
    for (let i = 0; i < length; ++i) {
      const x = Math.floor(Math.random() * length)
      const y = Math.floor(Math.random() * length)
      const temp = this.data.objectArray[x]
      this.data.objectArray[x] = this.data.objectArray[y]
      this.data.objectArray[y] = temp
    }
    this.setData({
      objectArray: this.data.objectArray
    })
  },
  addToFront: function (e) {
    const length = this.data.objectArray.length
    this.data.objectArray = [{ id: length, unique: 'unique_' + length }].concat(this.data.objectArray)
    this.setData({
      objectArray: this.data.objectArray
    })
  },
  data: {
    numberArray: [1, 2, 3, 4],
    objectArray: [
      { id: 5, unique: 'unique_5' },
      { id: 4, unique: 'unique_4' },
      { id: 3, unique: 'unique_3' },
      { id: 2, unique: 'unique_2' },
      { id: 1, unique: 'unique_1' },
      { id: 0, unique: 'unique_0' },
    ],
    cctv1info:{},
    cctv2info: { "cctv1": { "channelName": "CCTV-1 \u7efc\u5408", "program": [{ "t": "\u751f\u6d3b\u63d0\u793a2018-61", "st": 1522343940, "et": 1522344300, "showTime": "01:19", "eventType": "", "eventId": "", "duration": 360 }, { "t": "\u52a8\u7269\u4e16\u754c-2018-63\uff0845\u5206\u949f\uff09", "st": 1522344300, "et": 1522347120, "showTime": "01:25", "eventType": "", "eventId": "", "duration": 2820 }, { "t": "\u665a\u95f4\u65b0\u95fb", "st": 1522347120, "et": 1522348920, "showTime": "02:12", "eventType": "", "eventId": "", "duration": 1800 }, { "t": "\u7cbe\u5f69\u4e00\u523b-2018-84\u7ecf\u5178\u548f\u6d41\u4f20\u5b8c\u6574\u7248\u738b\u529b\u5b8f\u4f59\u5c11\u7fa4\u8d75\u7167", "st": 1522348920, "et": 1522349760, "showTime": "02:42", "eventType": "", "eventId": "", "duration": 840 }, { "t": "2017\u6311\u6218\u4e0d\u53ef\u80fd\u7b2c\u4e09\u5b63-\u7b2c\u516b\u671f\u91cd\u64ad", "st": 1522349760, "et": 1522355340, "showTime": "02:56", "eventType": "", "eventId": "", "duration": 5580 }, { "t": "\u4eca\u65e5\u8bf4\u6cd5-2018-88", "st": 1522355340, "et": 1522357020, "showTime": "04:29", "eventType": "", "eventId": "", "duration": 1680 }, { "t": "\u65b0\u95fb\u8054\u64ad", "st": 1522357020, "et": 1522358820, "showTime": "04:57", "eventType": "", "eventId": "", "duration": 1800 }, { "t": "\u4eba\u4e0e\u81ea\u7136-2018-89", "st": 1522358820, "et": 1522360800, "showTime": "05:27", "eventType": "", "eventId": "", "duration": 1980 }, { "t": "\u671d\u95fb\u5929\u4e0b", "st": 1522360800, "et": 1522370280, "showTime": "06:00", "eventType": "", "eventId": "", "duration": 9480 }, { "t": "\u751f\u6d3b\u65e9\u53c2\u8003-\u7279\u522b\u8282\u76ee\uff08\u751f\u6d3b\u5708\uff092018-57", "st": 1522370280, "et": 1522373310, "showTime": "08:38", "eventType": "", "eventId": "", "duration": 3030 }, { "t": "\u6362\u4e86\u4eba\u95f4\u7b2c32\u96c6", "st": 1522373310, "et": 1522376280, "showTime": "09:28", "eventType": "", "eventId": "", "duration": 2970 }, { "t": "\u6362\u4e86\u4eba\u95f4\u7b2c33\u96c6", "st": 1522376280, "et": 1522379205, "showTime": "10:18", "eventType": "", "eventId": "", "duration": 2925 }, { "t": "\u6362\u4e86\u4eba\u95f4\u7b2c34\u96c6", "st": 1522379205, "et": 1522382400, "showTime": "11:06", "eventType": "", "eventId": "", "duration": 3195 }, { "t": "\u65b0\u95fb30\u5206", "st": 1522382400, "et": 1522384660, "showTime": "12:00", "eventType": "", "eventId": "", "duration": 2260 }, { "t": "\u4eca\u65e5\u8bf4\u6cd5-2018-89", "st": 1522384660, "et": 1522387135, "showTime": "12:37", "eventType": "", "eventId": "", "duration": 2475 }, { "t": "\u6211\u7684\u7ee7\u7236\u662f\u5076\u50cf\u7b2c15\u96c6", "st": 1522387135, "et": 1522389945, "showTime": "13:18", "eventType": "", "eventId": "", "duration": 2810 }, { "t": "\u6211\u7684\u7ee7\u7236\u662f\u5076\u50cf\u7b2c16\u96c6", "st": 1522389945, "et": 1522392845, "showTime": "14:05", "eventType": "", "eventId": "", "duration": 2900 }, { "t": "\u6211\u7684\u7ee7\u7236\u662f\u5076\u50cf\u7b2c17\u96c6", "st": 1522392845, "et": 1522396340, "showTime": "14:54", "eventType": "", "eventId": "", "duration": 3495 }, { "t": "\u6211\u7684\u7ee7\u7236\u662f\u5076\u50cf\u7b2c18\u96c6", "st": 1522396340, "et": 1522399465, "showTime": "15:52", "eventType": "", "eventId": "", "duration": 3125 }, { "t": "\u7b2c\u4e94\u6279\u4e2d\u56fd\u68a6\u6b4c\u66f2\uff0830\u9996\uff09-\u4ffa\u4eec\u7684\u8d34\u5fc3\u4eba", "st": 1522399465, "et": 1522400140, "showTime": "16:44", "eventType": "", "eventId": "", "duration": 675 }, { "t": "\u7b2c\u4e00\u52a8\u753b\u4e50\u56ed-2018-193", "st": 1522400140, "et": 1522402540, "showTime": "16:55", "eventType": "", "eventId": "", "duration": 2400 }, { "t": "\u7b2c\u4e00\u52a8\u753b\u4e50\u56ed-2018-194", "st": 1522402540, "et": 1522406165, "showTime": "17:35", "eventType": "", "eventId": "", "duration": 3625 }, { "t": "\u7b2c\u4e00\u52a8\u753b\u4e50\u56ed-2018-195", "st": 1522406165, "et": 1522406935, "showTime": "18:36", "eventType": "", "eventId": "", "duration": 770 }, { "t": "\u7b2c\u4e00\u52a8\u753b\u4e50\u56ed-2018-132", "st": 1522406935, "et": 1522407600, "showTime": "18:48", "eventType": "", "eventId": "", "duration": 665 }, { "t": "\u65b0\u95fb\u8054\u64ad", "st": 1522407600, "et": 1522410050, "showTime": "19:00", "eventType": "", "eventId": "", "duration": 2450 }, { "t": "\u7126\u70b9\u8bbf\u8c08", "st": 1522410050, "et": 1522411715, "showTime": "19:40", "eventType": "", "eventId": "", "duration": 1665 }, { "t": "\u4fe1\u4e2d\u56fd-2018-4", "st": 1522411715, "et": 1522416740, "showTime": "20:08", "eventType": "", "eventId": "", "duration": 5025 }, { "t": "\u7cbe\u5f69\u4e00\u523b-2018-88\u7ecf\u5178\u548f\u6d41\u4f20\u8282\u9009\u8c2d\u7ef4\u7ef4", "st": 1522416740, "et": 1522418380, "showTime": "21:32", "eventType": "", "eventId": "", "duration": 1640 }, { "t": "\u665a\u95f4\u65b0\u95fb", "st": 1522418380, "et": 1522420815, "showTime": "21:59", "eventType": "", "eventId": "", "duration": 2435 }, { "t": "\u661f\u5149\u5927\u90532018-14 \u7b2c\u4e00\u671f\u6708\u8d5b", "st": 1522420815, "et": 1522425540, "showTime": "22:40", "eventType": "", "eventId": "", "duration": 4725 }] } },
    
    student1Score:{yuwen:83,shuxue:52,english:49,huaxue:77},
    student2Score: { yuwen: 83, shuxue: 52, english: 49, lishi: 77 },
    notice:"永恒的真理 时代的篇章",
    count:0,
    score:12,
    names:["zhangsan","lisi","wangwu"],
    text: 'init data',
    num: 0,
    array: [{ text: 'init data' }],
    object: {
      text: 'init data'
    }
  },
  onLoad:function(){
    var thispage = this;

    setTimeout(function () {
      thispage.setData({
        cctv1info: thispage.data.cctv2info
      });
    }, 3000);

    /*
    wx.showLoading({
      title: '加载中',
      success:function(){
        setTimeout(function () {
          thispage.setData({
            cctv1info: thispage.data.cctv2info
          });
          wx.hideLoading()
        },3000);
      }
    })
    */
  },

  add:function(){
    this.data.names.push("田七");
    this.setData({
      count:this.data.count+1,
      names:this.data.names
    });
  },
  changeText: function () {
    // this.data.text = 'changed data'  // bad, it can not work
    this.setData({
      text: 'changed data'
    })
  },
  changeNum: function () {
    this.data.num = 1
    this.setData({
      num: this.data.num
    })
  },
  changeItemInArray: function () {
    // you can use this way to modify a danamic data path
    this.setData({
      'array[0].text': 'changed data'
    })
  },
  changeItemInObject: function () {
    this.setData({
      'object.text': 'changed data'
    });
  },
  addNewField: function () {
    this.setData({
      'newField.text': 'new data'
    })
  },
  addHehe: function () {
    this.setData({
      'hehe.haha.xixi.o': '我的个娘哎！'
    })
  }
})